/*
 * @Author: zhangfeng
 * @Date: 2023-12-28 17:06:30
 * @LastEditTime: 2023-12-29 17:16:59
 * @LastEditors: zhangfeng
 * @Description:
 * @FilePath: \nodeapi\src\server\role-premission.server.js
 * © 2023 张峰，All rights reserved.
 */
const RolePremission = require("../model/role-menus.model");
const { Op, where } = require("sequelize");
class RolePremissionServer {
  async createServer(rolePremissArray) {
    const result = await RolePremission.bulkCreate(rolePremissArray);
    return result;
  }

  async deleteRolePremissionServer(roleId) {
    let whereOpt = {};
    if (Array.isArray(roleId)) {
      whereOpt = {
        roleId: {
          [Op.in]: roleId,
        },
      };
    } else {
      whereOpt = {
        roleId: roleId,
      };
    }
    const result = await RolePremission.destroy({
      where: whereOpt,
    });
    return result;
  }

  async getRolePremissionServer(roleId) {
    let whereOpt = {};
    if (Array.isArray(roleId)) {
      whereOpt = {
        roleId: {
          [Op.in]: roleId,
        },
      };
    } else {
      whereOpt = {
        roleId: roleId,
      };
    }
    const result = await RolePremission.findAll({
      where: whereOpt,
    });
    return result;
  }
}

module.exports = new RolePremissionServer();
